package com.teach.config.listener;

import java.net.InetAddress;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

import com.teach.config.Config;
import com.teach.util.ELTools;

/**
 * <pre>
 * TODO : 系统监听器
 * - 注意：需要在启动类中配置@ServletComponentScan
 * ClassName : com.teach.config.listener.SystemListener
 * Author : J.L.Zhou
 * Date : 2020-11-08 12:02 
 * Version : V1.0
 * Copyright 2020 jlzhou.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes</pre>
 */
@WebListener
public class SystemListener implements ServletContextListener {

	private static final Logger log = LoggerFactory.getLogger(SystemListener.class);
	
	@Autowired
	private Config config;
	
	@Autowired
	private Environment environment;
	
	@Autowired
	private ELTools tools;
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		/*
		 *┏━┓
		 *┃ ┃
		 *┗━┛ 
		 */
		sce.getServletContext().setAttribute("t", tools);
		log.info("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
		log.info("┃ 欢迎使用<"+config.systemName+">");
		try {
			log.info("┃ 访问地址：http://"+InetAddress.getLocalHost().getHostAddress()+":"+environment.getProperty("server.port"));
		}catch (Exception e) {
			log.info("┃ 访问地址：http://127.0.0.1:"+environment.getProperty("server.port"));
		}
		log.info("┃ ELTools在jsp中使用：${t.xxx()}");
		log.info("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
		
	}
}
